
// 引入AES.js
var baseJs = require("../../common/base.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgUrl: baseJs.imgUrl,
    id: "",
    newsList: [],
    pageIndex:1,
    state:"",
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.setData({
      id: options.id,
    })
    wx.setNavigationBarTitle({
      title: options.title
    })
    this.GetStateBarList();
  },





  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {
    this.data.pageIndex++;
    this.GetStateBarList();
  },

  // 
  GetStateBarList: function () {
    var that = this;
    var uid = this.data.uid;
    var id = this.data.id;
    var pageIndex = this.data.pageIndex;
    var newsList = this.data.newsList;
    wx.request({
      url: baseJs.api + baseJs.encryUrl("method=GetStateBarList&ProvinceName=&CityName=&DistinctName=&BarType=" + id + "&PageSize=10&PageIndex=" + pageIndex),
      success: function (res) {
        var json = JSON.parse(baseJs.decryUrl(res.data)).ResultData;
        for (var i = 0; i < json.length; i++) {
          json[i].images = json[i].images.split(";");
          newsList.push(json[i])
        }
        that.setData({
          newsList: newsList,
        })
        console.log(newsList);
        if (json.length == 10) {
          that.setData({
            state: 'loadMore',
          })
        } else if (json.length == 0 && pageIndex == 1) {
          that.setData({
            state: 'noData',
          })
        } else if (json.length < 10) {
          that.setData({
            state: 'noMore',
          })
        } else if (json.length == 0 && pageIndex > 1) {
          that.setData({
            state: 'noMore',
          })
        }
      }
    })
  },
})